import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path';

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig({
    plugins: [
        vue(),
        AutoImport({
            resolvers: [ElementPlusResolver()],
        }),
        Components({
            resolvers: [ElementPlusResolver()],
        }),
    ],
    resolve: {
        alias: {
            '@': path.resolve(__dirname, 'src'),
            "@components": path.resolve(__dirname, 'src/components'),
        }
    },
    // 开发服务器
    server: {
        host: '0.0.0.0', // 允许通过本机IP地址访问
        // 配置代理
        proxy: {
            // 将所有路径以'/api'开头的请求，进行代理转发
            '/api': {
                // 配置真正要请求的目标服务器地址
                target: 'http://nocat.life:3011',
                // 允许跨域访问
                changeOrigin: true,
                // 将转发后的请求路径中的/api去掉
                rewrite: path => path.replace(/^\/api/, '')
            }
        }
    }
})
